﻿/*********************************************
 创建者：  george
 创建时间：2016-11-16
 功能说明：返回全国省份信息
 ********************************************/
using com.nm.ApiServer;
using com.nm.ApiServer.Attributes;
using com.nm.Attributes;
using com.nm.db.Models.Systems;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseAPI
{
    [Description("返回全国省份信息")]
    public class AreaHandler : BaseHandler
    {
        [Description("获取地址信息")]
        [ReturnType(typeof(IList<Address>))]
        public ApiResult Get([ParamDescription("父ID")]int parentId = 0)
        {
            var dc = new SysEntities();
            var query = dc.t_area.Where(t => t.IfStop == "0" && t.ParentID == parentId);
            if (!query.Any())
                return Success(new string[] { });
            var result = query.Select(o => new Address
            {
                ID = o.AreaID,
                Name = o.ChiName,
                PID = (int)o.ParentID
            });
            return Success(result);
        }
    }

    [Description("获取地址信息")]
    public class Address
    {
        [ParamDescription("ID")]
        public int ID { get; set; }

        [ParamDescription("名称")]
        public string Name { get; set; }

        [ParamDescription("父ID")]
        public int PID { get; set; }
    }
}
